package com.mi.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.mi.bean.Goods;
import com.mi.service.impl.AddGoodsImpl;
import com.mi.utils.MyUtils;

/**
 * 实现文件上传，将商品上传到服务器中，并向数据库商品表中提交商品信息
 */
@WebServlet("/AddProjects")
@MultipartConfig(maxFileSize=1024*1024*5)
public class addProjects extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		// 1、接收表单数据
				Goods goodB = MyUtils.convertFormData2Bean(request, Goods.class);
				// 2、调用service层进行数据保存
				int i = MyUtils.getInstance(AddGoodsImpl.class).saveOrUpdateAdminInf(goodB);
				// 3、根据保存处理结果进行页面转发
				if(i>0) {
					// 保存成功
					request.getRequestDispatcher("WEB-INF/logined/adminManage/GoodsAddOkJump.jsp").forward(request, response);
				}else {
					// 保存失败
					request.getRequestDispatcher("WEB-INF/logined/adminManage/GoodsAddFailJump.jsp").forward(request, response);
				}
		
	}

}
